package mongo.db.clients.firsts;

import java.net.UnknownHostException;
import java.util.concurrent.Callable;

import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;
import com.mongodb.MongoClient;

public class Multiply implements Callable<Integer> {

	String ip;

	/*
	 * public static void main(String[] args) throws Exception { SpeedTest test
	 * = new SpeedTest(); test.call(); }
	 */

	@Override
	public Integer call() {

		try {
//			System.out.println("thread : " + ip);

			MongoClient client = new MongoClient("202.191.136.234", 27017);

			DB db = client.getDB("netflowdb");
			DBCollection collection = db.getCollection("netflow_column_list");
			DBCollection outCollection = db.getCollection("gen_netflow");

			BasicDBObject query = new BasicDBObject("routerip", ip);
			DBCursor iter = collection.find(query);
			System.out.println(ip + ":" + iter.length());

/*			while (iter.hasNext()) {
				DBObject doc = iter.next();
//				System.out.println("in : " + doc);
				if (doc.containsField("routerip")) {
					String ip = (String) doc.get("routerip");
					doc.removeField("_id");
					doc.removeField("routerip");
					for (int i = 1; i <= 5; i++) {
						doc.put("routerip", i + ip);
//						System.out.println("out : " + doc);
						outCollection.insert(doc);
						doc.removeField("routerip");
						doc.removeField("_id");
					}
				}
			}
*/
			iter.close();
			client.close();
			client = null;
		} catch (Exception e) {
			e.printStackTrace();
		}

		return 1;
	}

	public Multiply(String ip) {
		this.ip = ip;
	}

}
